package Action;

import Service.OrderManageService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class OrderManageAction extends ActionSupport {
    public final static String ACTION_ADD = "add";
    public final static String ACTION_QUERY = "query";

    private OrderManageService manageService;
    private String action = "";
    private String status = "";
    private List manageList;

    //params
    private String user_name = "";
    private String purchaseNo = "";
    private String service_type = "";
    private String service_detail = "";

    public OrderManageService getManageService() {
        return manageService;
    }

    public void setManageService(OrderManageService manageService) {
        this.manageService = manageService;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getUser_name() {
        return user_name;
    }

    public void setUser_name(String user_name) {
        this.user_name = user_name;
    }

    public String getAction() {
        return action;
    }

    public void setAction(String action) {
        this.action = action;
    }

    public List getManageList() {
        return manageList;
    }

    public void setManageList(List manageList) {
        this.manageList = manageList;
    }

    public String getPurchaseNo() {
        return purchaseNo;
    }

    public void setPurchaseNo(String purchaseNo) {
        this.purchaseNo = purchaseNo;
    }

    public String getService_type() {
        return service_type;
    }

    public void setService_type(String service_type) {
        this.service_type = service_type;
    }

    public String getService_detail() {
        return service_detail;
    }

    public void setService_detail(String service_detail) {
        this.service_detail = service_detail;
    }

    public String execute(){
        user_name = (String) ActionContext.getContext().getSession().get("user_name");
        if (action.equals(ACTION_ADD)){
            Map<String,String> params = new HashMap();
            params.put("purchaseNo",purchaseNo);
            params.put("service_type",service_type);
            params.put("service_detail",service_detail);
            params.put("user_name",user_name);
            status = manageService.addOrderManage(params);
            if (status .equals(OrderManageService.STATUS_SUCCESS))
                return "add_success";
            else if (status.equals(OrderManageService.STATUS_FAIL))
                return "add_fail";
            else
                return ERROR;
        }else if (action.equals(ACTION_QUERY)){
            manageList = manageService.queryOrderManage(user_name);
            return "query_success";
        }else
            return ERROR;
    }
}

//http://localhost:8080/orderManageAction?action=add&purchaseNo=0&service_type=cancel&service_detail=this_is_a_test